module SiteHelper

  def picture_table(pictures, options={:per_row => 5, :generate_remote_calls => true})
    per_row = options[:per_row]
    generate_remote_calls = options[:generate_remote_calls]
    lst = Array.new
    lst[0] = '<table class="picture_list">'
    current_column = 0
    pictures.each do |picture|
      if current_column == 0
	lst[lst.length] = '<tr>'
      end
      if generate_remote_calls == true
	lst[lst.length] = '<td class="thumbnail" onMouseover="' + remote_function(:update => "pp",  :url => {:controller => "picture", :action => "preview", :id => picture.id}) + '">'
      else
	lst[lst.length] = '<td class="thumbnail">'
      end
      lst[lst.length] = link_to image_tag("/images/storage/#{picture.id}/small.jpg"), :controller => 'picture', :action => 'show', :id => picture.id
      lst[lst.length] = '</td>'
      current_column += 1
      if current_column == per_row
	current_column = 0
	lst[lst.length] = '</tr>'
      end
    end
    lst[lst.length] = '</table>'
    
    return lst
  end

  def user_table(users)
    lst = Array.new
    lst[0] = '<table>'
    lst[1] = '<tr><th>Nazwa użytkownika</th><th>Imię i nazwisko</th><th>Miasto</th><th>Kraj</th></tr>'
    users.each do |user|
      lst[lst.length] = '<tr>'
      lst[lst.length] = '<td>' + link_to(user.username, :controller => "site", :action => "gallery", :id => user.id, :page => 1) + '</td>'
      lst[lst.length] = '<td>' + user.full_name + '</td>'
      lst[lst.length] = '<td>' + user.city + '</td>'
      lst[lst.length] = '<td>' + user.country + '</td>'
      lst[lst.length] = '</tr>'
    end
    lst[lst.length] = '</table>'
    return lst
  end
end
